package iterator;

import iterator.exceptions.TupleUtilsException;
import iterator.exceptions.UnknowAttrType;

import java.io.IOException;

import global.AttrType;
import global.TupleOrder;

public abstract class pnodePQ {
	/** number of elements in the tree */
	protected int count;

	/** the field number of the sorting field */
	protected int fld_no;

	/** the attribute type of the sorting field */
	protected AttrType fld_type;

	/** the sorting order (Ascending or Descending) */
	protected TupleOrder sort_order;

	public pnodePQ() {
		// TODO Auto-generated constructor stub
	}

	abstract pnode deq();

	/**
	 * test if tree is empty
	 * 
	 * @return
	 */
	boolean empty() {

		return count == 0;
	}

	/**
	 * insert an element in the tree in the correct order
	 * 
	 * @param item
	 */
	abstract void enq(pnode item)throws IOException, UnknowAttrType, TupleUtilsException ;

	/**
	 * return the number of elements in the tree
	 * 
	 * @return
	 */
	int length() {
		return count;
	}

	/**
	 * compares two elements
	 * 
	 * @param a
	 * @param b
	 * @return
	 */
	public int pnodeCMP(pnode a, pnode b) throws IOException, UnknowAttrType,
			TupleUtilsException {
		int ans = TupleUtils.CompareTupleWithTuple(fld_type, a.tuple, fld_no,
				b.tuple, fld_no);
		return ans;
	}

	/**
	 * test whether the two elements are equal
	 * 
	 * @param a
	 * @param b
	 * @return
	 */
	boolean pnodeEQ(pnode a, pnode b) {
		return false;
	}

}
